<template>
  <div class="rightBodyContent">
    <div class="rightBodyContent-in">
      <!--      搜索组件-->
<!--      <SearchModle dataKey="licence" @searchFn="searchFn"></SearchModle>-->
      <!--      end-->
      <div class="mb-10">
        <div class="toplineBox">
          <div class="toplineBox-left">
            <el-button size="small" @click="addStudent()" type="primary"><i class="el-icon-plus"></i>添加公章</el-button>
          </div>
          <p class="numberline toplineBox-right">总{{page.total}}条</p>
        </div>
      </div>
      <!--本体列表，数据 -->
      <div class="table-body">
        <div class="table-body-box">
          <el-table
              ref="multipleTable"
              :data="arryList"
              :stripe="tableStyle.tableStripe"
              :border="tableStyle.tableBorder"
              tooltip-effect="dark"
              header-cell-class-name="table-text-c"
              style="width: 100%">
            <el-table-column
                prop="name"
                label="证照名称"
                align="center">
            </el-table-column>
<!--            <el-table-column-->
<!--                prop="create_time"-->
<!--                label="证照管理人"-->
<!--                align="center">-->
<!--              <template slot-scope="scope">-->
<!--                {{scope.row.user?scope.row.user.realname:'&#45;&#45;'}}-->
<!--              </template>-->
<!--            </el-table-column>-->
            <el-table-column
                align="center"
                label="操作"
                width="180">
              <template slot-scope="scope">
                <el-button type="primary" plain size="small" @click="addStudent(scope.row.id)">查看详情</el-button>
                <el-button type="danger" plain size="small" @click="deleteList(scope.$index)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <!--工具条 分页-->
      <el-col :span="24" class="toolbar">
        <el-pagination
            background
            layout="total, prev, pager, next"
            :total="page.total"
            :page-size="page.pagesize"
            @current-change="handleSizeChange">
        </el-pagination>
      </el-col>
    </div>
    <addEdit :visible.sync="detailVisible" :licenceId="licenceId" @InitFn="InitFn"></addEdit>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
import addEdit from "./addEdit";
import {sealDelete} from '@/api/admin/badge'
export default {
  components: {
    addEdit
  },
  data () {
    return {
      detailVisible: false,
      licenceId: 0,
      handleSelection: [],
      arryList: [], // 页面数据列表
      // 设置table样式
      tableStyle: tableoption,
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      indexOption: '',
      classesListNew: [],
      sectionList: [],
      classesList: [],
      // 搜索组件
      searchForm: {},
      parentsVisible: false,
      parentsOption: ''
    }
  },
  created () {
    this.InitFn()
  },
  methods: {
    // 初始化
    InitFn () {
      this.searchForm.p = this.page.pageindex
      this.$fetch(this.api.seal.index, this.searchForm).then((response) => {
        if (response.code === 0) {
          this.arryList = JSON.parse(JSON.stringify(response.list.data))
          this.page.total = response.list.total
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    // 分页
    handleSizeChange (val) {
      this.page.pageindex = val
      this.InitFn()
    },
    // 搜索组件
    searchFn(option) {
      this.page.pageindex = 1
      this.searchForm = option
      this.InitFn()
    },
    addStudent (row) {
      this.licenceId = row || '';
      this.detailVisible = true;
    },
    deleteList(index){
      let this_ = this
      this.$confirm('此操作将删除 ' + this.arryList[index].name + ' 公章, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal: false,
        type: 'warning'
      }).then(() => {
        this_.deletFn(index)
      }).catch(() => {
      })
    },
    deletFn (index) {
      sealDelete({id: this.arryList[index].id}).then(res=>{
        console.log('res:', res)
        if(!res.code){
          this.$message.success(res.msg)
          this.InitFn()
        }
      })
    },
  },
  mounted () {},
}
</script>

<style scoped>

.wx-user-box-line img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin-right: 5px;
}

.wx-user-box-line {
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-wx {
  cursor: pointer;
  padding: 5px;
}

.btn-wx:hover {
  color: #1b8de5;
  text-decoration: underline;
}

.delet-wx {
  color: red;
  cursor: pointer;
}

.delet-wx:hover {
  text-decoration: underline;
}
</style>
